#include "beidouportobject.h"
#include "bdsetmodelthread.h"
#include "customcommandthread.h"
#include "dialogabout.h"
#include "framewindow.h"
#include "serialportsmanager.h"
#include "ui_mainwindow.h"
#include "recognize_mcu_com.h"
#include "beidoupower.h"
#include "dialogwait.h"

#include <QDateTime>
#include <QMessageBox>
#include <QMessageBox>
#include <QSerialPortInfo>
#include <QDebug>



FrameWindow::FrameWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    intialWindow();

    manualInitial = false;

    // setWindowIcon(QIcon(":/images/4gtet-logo.png"));//可执行程序图标
    setWindowIcon(QIcon(":/new/prefix1/images/Test-1.ico"));//可执行程序图标

}

FrameWindow::~FrameWindow()
{
    delete ui;
}

Ui::MainWindow *FrameWindow::getUI()
{
    return ui;
}

int FrameWindow::intialWindow()
{

    setWindowState(Qt::WindowMaximized);


    QStringList header;
    ui->tableWidgetCOMName->setColumnCount(2);//
    //ui->tableWidgetCOMName->setRowCount(20);//列数设置为与 headerText的行数相等

    ui->tableWidgetATCommand->setColumnCount(2);
    //ui->tableWidgetATCommand->setRowCount(20);


    ui->tableWidgetATCommand_result->setColumnCount(3);



    ui->tableWidgetCOMName->setWindowTitle("QTableWidget & Item");
    //ui->tableWidgetCOMName->resize(350, 200); //设置表格

    header<<"选择COM"<<"描述";
    ui->tableWidgetCOMName->setHorizontalHeaderLabels(header);
    ui->tableWidgetCOMName->setEditTriggers ( QAbstractItemView::NoEditTriggers );//表格不可编辑
    ui->tableWidgetCOMName->setColumnWidth(0,120);
    ui->tableWidgetCOMName->setColumnWidth(1,350);
    // ui->tableWidgetCOMName->setColumnWidth(1,int(ui->tableWidgetCOMName->size ().width ()/0.4));

    // ui->tableWidgetCOMName->setItem(0,0,new QTableWidgetItem("Jan"));
    // ui->tableWidgetCOMName->setItem(1,0,new QTableWidgetItem("Feb"));
    // ui->tableWidgetCOMName->setItem(2,0,new QTableWidgetItem("Mar"));
    // ui->tableWidgetCOMName->setItem(0,1,new QTableWidgetItem(QIcon("images/IED.png"), "Jan's month"));
    // ui->tableWidgetCOMName->setItem(1,1,new QTableWidgetItem(QIcon("images/IED.png"), "Feb's month"));
    // ui->tableWidgetCOMName->setItem(2,1,new QTableWidgetItem(QIcon("images/IED.png"), "Mar's month"));
    ui->tableWidgetCOMName->show();

    header.clear();
    header<<"命令"<<"名称";
    ui->tableWidgetATCommand->setHorizontalHeaderLabels(header);
    ui->tableWidgetATCommand->setEditTriggers ( QAbstractItemView::NoEditTriggers );//表格不可编辑
    ui->tableWidgetATCommand->setWindowTitle("AT commond Area");
    ui->tableWidgetATCommand->setColumnWidth(0,140);
    ui->tableWidgetATCommand->setColumnWidth(1,int(ui->tableWidgetATCommand->size ().width ()/1.7));
    ui->tableWidgetATCommand->show();

    header.clear();
    header<<"COM"<<"数据"<<"结果";
    ui->tableWidgetATCommand_result->setHorizontalHeaderLabels(header);
    ui->tableWidgetATCommand_result->setEditTriggers ( QAbstractItemView::NoEditTriggers );//表格不可编辑
    ui->tableWidgetATCommand_result->setWindowTitle("AT commond Area");
    ui->tableWidgetATCommand_result->setColumnWidth(0,90);
    ui->tableWidgetATCommand_result->setColumnWidth(1,int(ui->tableWidgetATCommand_result->size ().width ()/0.8));
    ui->tableWidgetATCommand_result->show();

    loadATCommand();
    app->processEvents();        //手动开启QT的事件机制(一般是在a.exec()处最后会进入事件分发)
    initialManualPage();



    //默认 自动按钮 红色字体
    ui->pushButton_AutoMode->setStyleSheet("color: red");



    qDebug() <<"MAIN Thread: "<<QThread::currentThread()<< "PID is "<< QThread::currentThreadId();

    return 0;
}

void FrameWindow::initialManualPage(){

    QStringList header;
    header<<"选择"<<"AT command";

    ui->tableWidget_custom_command->setColumnCount(2);//
    ui->tableWidget_custom_command->setHorizontalHeaderLabels(header);
    // ui->tableWidgetATCommand->setEditTriggers ( QAbstractItemView::NoEditTriggers );//表格不可编辑

    ui->tableWidget_custom_command->setWindowTitle("Cusom commond");
    ui->tableWidget_custom_command->setColumnWidth(0,50);
    // ui->tableWidget_custom_command->setColumnWidth(1,int(ui->tableWidget_custom_command->size ().width ()));
    ui->tableWidget_custom_command->setColumnWidth(1,300);

    ui->tableWidget_custom_command->show();

    int i =0;
    QString customComm;



    customComm = "at+cpin?";
    ui->tableWidget_custom_command->insertRow(i);

    QTableWidgetItem *check = new QTableWidgetItem();
    check->setCheckState(Qt::Checked);
    ui->tableWidget_custom_command->setItem(i, 0,check); //插入复选框
    ui->tableWidget_custom_command->setItem(i,1,new QTableWidgetItem(customComm));

    i++;
    customComm = "at$myccid";
    ui->tableWidget_custom_command->insertRow(i);
    check = new QTableWidgetItem();
    check->setCheckState(Qt::Checked);
    ui->tableWidget_custom_command->setItem(i, 0,check); //插入复选框
    ui->tableWidget_custom_command->setItem(i,1,new QTableWidgetItem(customComm));

    i++;
    customComm = "at+cgreg?";
    ui->tableWidget_custom_command->insertRow(i);
    check = new QTableWidgetItem();
    check->setCheckState(Qt::Checked);
    ui->tableWidget_custom_command->setItem(i, 0,check); //插入复选框
    ui->tableWidget_custom_command->setItem(i,1,new QTableWidgetItem(customComm));

    i++;
    customComm = "at+csq";
    ui->tableWidget_custom_command->insertRow(i);
    check = new QTableWidgetItem();
    check->setCheckState(Qt::Checked);
    ui->tableWidget_custom_command->setItem(i, 0,check); //插入复选框
    ui->tableWidget_custom_command->setItem(i,1,new QTableWidgetItem(customComm));

    i++;
    customComm = "at+cgatt?";
    ui->tableWidget_custom_command->insertRow(i);
    check = new QTableWidgetItem();
    check->setCheckState(Qt::Checked);
    ui->tableWidget_custom_command->setItem(i, 0,check); //插入复选框
    ui->tableWidget_custom_command->setItem(i,1,new QTableWidgetItem(customComm));

    i++;
    customComm = "at$mysysinfo";
    ui->tableWidget_custom_command->insertRow(i);
    check = new QTableWidgetItem();
    check->setCheckState(Qt::Checked);
    ui->tableWidget_custom_command->setItem(i, 0,check); //插入复选框
    ui->tableWidget_custom_command->setItem(i,1,new QTableWidgetItem(customComm));

    for (int j=0;j<2;j++) {
        i++;
        customComm = "";
        ui->tableWidget_custom_command->insertRow(i);
        check = new QTableWidgetItem();
        check->setCheckState(Qt::Unchecked);
        ui->tableWidget_custom_command->setItem(i, 0,check); //插入复选框
        ui->tableWidget_custom_command->setItem(i,1,new QTableWidgetItem(customComm));
    }


}

void FrameWindow::onSendData(QString value)
{
    ui->textEditReceive->append(value);
}

void FrameWindow::showReceiveData(QByteArray value)
{
    QString startTime= QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz");
    ui->textEditReceive->append(startTime);
    ui->textEditReceive->append(value);

    //QTextCursor cursor = ui->textEditReceive->textCursor();
    ui->textEditReceive->moveCursor(QTextCursor::End);
}


void FrameWindow::onReceiveResult(QString COMName, QString rev, int result)
{
    int rows = ui->tableWidgetATCommand_result->rowCount();
    ui->tableWidgetATCommand_result->insertRow(rows);
    ui->tableWidgetATCommand_result->setItem(rows,0,new QTableWidgetItem(COMName));
    ui->tableWidgetATCommand_result->setItem(rows,1,new QTableWidgetItem(rev));
    ui->tableWidgetATCommand_result->setItem(rows,2,new QTableWidgetItem(result==0? "成功":"失败"));
}



void FrameWindow::onAutoTestEnd()
{
    ui->pushButtonAutoStart->setText("开始测试");
}

void FrameWindow::onReceivdBeidou(QByteArray receivArea)
{
    //QDateTime::currentDateTime().toString("[yyyy-MM-dd hh:mm:ss zzz]");

    QString strRec;
    strRec.prepend(receivArea);
    ui->textEdit_beidouReceive->append(QDateTime::currentDateTime().toString("[yyyy-MM-dd hh:mm:ss zzz]")+strRec);

    ui->textEdit_beidouReceive->moveCursor(QTextCursor::End);
}

void FrameWindow::onTransfer_result(QStringList result)
{
    //1 $--GGA 字符串 消息 ID，GGA 语句头，’--‘为系统标识
    //2 UTCtime hhmmss.sss 当前定位的 UTC 时间

    //3 lat ddmm.mmmm 纬度，前 2 字符表示度，后面的字符表示分
    //4 uLat 字符 纬度方向：N-北，S-南

    // 5 lon dddmm.mmmm 经度，前 3 字符表示度，后面的字符表示分
    // 6，uLon 字符 经度方向：E-东，W-西

    // 10 msl 数值 海拔高度，即接收机天线相对于大地水准面的高度

    QString tmp1,tmp2;


    if(result.length()>=15){

        tmp1 =result.at(4).left(3)+"º";// °，º度
        tmp2 = result.at(4).mid(3)+"′";// ′，'分

        // 经度方向
        ui->textEdit_Longitudwe->setText(result.at(5)+" - "+tmp1+tmp2);//

        //纬度方向：N-北，S-南
        tmp1 =result.at(2).left(2)+"º";
        tmp2 = result.at(2).mid(2)+"′";
        ui->textEdit_Latitude->setText(result.at(3)+" - "+tmp1+tmp2);//
        // 海拔
        ui->textEdit_High->setText(result.at(9)+"m");
        // 时间

        QString strtime =result.at(1);
        int hh =strtime.left(2).toInt()+8; //UTC时间 to 北京时间
        QString temp =QString::number(hh)+":"+strtime.mid(2,2)+":"+strtime.mid(4,2)+"."+strtime.right(3);

        ui->textEdit_Time->setText(temp);

    }


}



void FrameWindow::onSendCustomResult(QString COMName, QString rev, int result)
{
    result =0;
    ui->textEdit_manual_receive->append( "接收"+COMName );
    ui->textEdit_manual_receive->append(rev);
    ui->textEdit_manual_receive->moveCursor(QTextCursor::End);
}

void FrameWindow::onSendCustom(QString COMName, QString sent)
{
    ui->textEdit_manual_receive->append("发送"+COMName+sent);
    ui->textEdit_manual_receive->moveCursor(QTextCursor::End);

}

void FrameWindow::onManualSendAndReceive(QString COMName, QString rev, QString  rw)
{
    ui->textEdit_manual_receive->append(rw+COMName);
    ui->textEdit_manual_receive->append(rev);


    ui->textEdit_manual_receive->moveCursor(QTextCursor::End);
}


int FrameWindow::getCOMList(){

    if(!COMLists.isEmpty()){
        COMLists.clear();
    }

    // 获取用户选择的串口
    QString COMName;
    int rowCount =  ui->tableWidgetCOMName->rowCount();
    for (int i=0;i<rowCount;i++) {

        if(ui->tableWidgetCOMName->item(i,0)->checkState()==Qt::Unchecked){
            continue;
        }

        COMName = ui->tableWidgetCOMName->item(i,0)->text();
        COMLists.append(COMName);
    }

    return 0;
}

int FrameWindow::getManualCommand(){
    ManualCommand =  ui->textEdit_manualSend->toPlainText()+"\r";
    return 0;
}

int FrameWindow::getCustomCommands(){

    if(!customCommands.isEmpty()){
        customCommands.clear();
    }

    // 获取用户选择的测试项目
    int commands =  ui->tableWidget_custom_command->rowCount();
    for(int i =0; i<commands;i++){
        if(ui->tableWidget_custom_command->item(i,0)->checkState()==Qt::Checked){

            ATCommandItem comm;
            comm.atCommand = ui->tableWidget_custom_command->item(i,1)->text()+"\r";
            comm.check = true;
            customCommands.append(comm);
        }
    }

    return  0;
}

int FrameWindow::getUserSelect(){



    QLinkedList<ATCommandItem>::iterator iter;
    for (iter=commandList.begin();iter!=commandList.end();iter++)
    {
        iter->check = true;
    }

    return 0;
}

int FrameWindow::clearShow(){

    ui->tableWidgetATCommand_result->setRowCount(0);
    ui->tableWidgetATCommand_result->clearContents();

    return 0;
}

int FrameWindow::loadATCommand()
{
    //插入一行


    ATCommandItem item;

    item.atCommand = "at+cpin?\r";
    item.atName ="获取SIM卡状态";
    item.resposeData = "+CPIN: READY";
    item.resposeGood = "OK";
    item.resposeBad = "ERROR";
    commandList.append(item);


    item.atCommand = "at$myccid\r";
    item.atName ="获取SIM卡序列号";
    item.resposeData = "$MYCCID:";
    item.resposeGood = "OK";
    item.resposeBad = "ERROR";
    commandList.append(item);


    item.atCommand = "at+cgreg?\r";
    item.atName ="获取网络注册状态";
    item.resposeData = "+CGREG: 0,1";
    item.resposeGood = "OK";
    commandList.append(item);

    item.atCommand = "at+csq\r";
    item.atName ="获取信号强度";
    item.resposeData = "+CSQ:"; //+CSQ: 13,99
    item.resposeGood = "OK";
    commandList.append(item);

    //at+cgatt?

    item.atCommand = "at+cgatt?\r";
    item.atName ="查看网络附着状态";
    item.resposeData = "+CGATT:"; //+CGATT: 1
    item.resposeGood = "OK";
    commandList.append(item);

    //at$mysysinfo
    item.atCommand = "at$mysysinfo\r";
    item.atName ="网络制式查询";
    item.resposeData = "$MYSYSINFO:"; //$MYSYSINFO: 3,02
    item.resposeGood = "OK";
    commandList.append(item);


    int i =0;
    foreach ( item,commandList) {

        ui->tableWidgetATCommand->insertRow(i);

        //QTableWidgetItem *check = new QTableWidgetItem();
        // check->setCheckState(Qt::Checked); // check->setCheckState(Qt::Unchecked);

        //ui->tableWidgetATCommand->setItem(i, 0,check); //插入复选框
        ui->tableWidgetATCommand->setItem(i,0,new QTableWidgetItem(item.atCommand));
        ui->tableWidgetATCommand->setItem(i,1,new QTableWidgetItem(item.atName));
        //ui->tableWidgetATCommand->setItem(i,2,new QTableWidgetItem("AT命令"));

        i++;
    }

    return 0;
}



void FrameWindow::on_pushButtonCOMName_clicked()
{
    ui->tableWidgetCOMName->setRowCount(0);
    ui->tableWidgetCOMName->clearContents();



    Recognize_MCU_COM *mcu_com =new Recognize_MCU_COM(this);
    mcu_com->start();
    //mcu_com.wait();



}

QString FrameWindow::recognize_4G_COM(QString previous)
{

    QString portDescription;
    QString manufacturer;
    QString channalName;
    QString recognyzedName;
    bool  recognize =false;
    int row =0;


    qDebug() <<"FrameWindow::recognize_4G_COM() THREAD : "<<QThread::currentThread();
    // 有方
    manufacturer ="NEOWAY HS-USB TTY AT 3C93";

    foreach (const QSerialPortInfo &portInfo, QSerialPortInfo::availablePorts())
    {
        portDescription=  portInfo.description();

        if(!portDescription.isEmpty()&& manufacturer.contains(portDescription,Qt::CaseInsensitive)){

            recognize = true;

            if(previous == "")//第一次识别前，没有通道串口
            { // 识别出是第1个串口
                channalName = "通道1";
                recognyzedName = portInfo.portName();
            }else if(previous == portInfo.portName()){
                continue;// 第二次识别时，已经识别出一个串口
            }else{
                recognyzedName = portInfo.portName();
                channalName = "通道2";
            }




            QTableWidgetItem *check = new QTableWidgetItem();
            check->setText(portInfo.portName());
            check->setCheckState(Qt::Checked);

            row = ui->tableWidgetCOMName->rowCount();
            ui->tableWidgetCOMName->insertRow(row);
            ui->tableWidgetCOMName->setItem(row, 0,check); //插入复选框
            ui->tableWidgetCOMName->setItem(row,1,new QTableWidgetItem(channalName));

            recognize_COM_Name = recognyzedName;
            /*
            mutex_ui_update.lock();
            waitCon_ui_update.wakeAll();
            qDebug() << QDateTime::currentDateTime().toString("[yyyy-MM-dd hh:mm:ss zzz]") <<
                        " Condition wake all !";
            mutex_ui_update.unlock();

            */
            break;
        }
    }



    if(recognize){
        return recognyzedName;
    }

    // 思极/华为
    manufacturer ="HUAWEI Mobile Connect - PC UI Interface";
    channalName ="SC53502MS";
    foreach (const QSerialPortInfo &portInfo, QSerialPortInfo::availablePorts())
    {
        portDescription=  portInfo.description();

        //Qt::CaseInsensitive CaseSensitive
        if( !portDescription.isEmpty()
                && manufacturer.contains(portDescription,Qt::CaseInsensitive)){

            recognize=true;

            if(previous == "")//第一次识别前，没有通道串口
            { // 识别出是第1个串口
                channalName = "通道1";
                recognyzedName = portInfo.portName();

            }else if(previous == portInfo.portName()){
                continue;// 第二次识别时，已经识别出一个串口

            }else{
                recognyzedName = portInfo.portName();
                channalName = "通道2";
            }

            QTableWidgetItem *check = new QTableWidgetItem();
            check->setText(portInfo.portName());
            check->setCheckState(Qt::Checked);

            row = ui->tableWidgetCOMName->rowCount();
            ui->tableWidgetCOMName->insertRow(row);
            ui->tableWidgetCOMName->setItem(row, 0,check); //插入复选框
            ui->tableWidgetCOMName->setItem(row,1,new QTableWidgetItem(channalName));

            recognize_COM_Name = recognyzedName;
            mutex_ui_update.lock();
            waitCon_ui_update.wakeAll();
            qDebug() << QDateTime::currentDateTime().toString("[yyyy-MM-dd hh:mm:ss zzz]") <<
                        " Condition wake all !";
            mutex_ui_update.unlock();

            break;

        }
    }


    return recognyzedName;


}

void FrameWindow::UI_top_message_box(QString titie,QString text )
{
    QMessageBox::warning(this,titie,text);
}




void FrameWindow::on_pushButtonAutoStart_clicked()
{
    if(ui->pushButtonAutoStart->text()=="结束测试"){
        serialThread->isTerminate = true;
        serialThread->quit();
        serialThread->wait();
        //delete serialThread;
        ui->pushButtonAutoStart->setText("开始测试");

        return;
    }

    if( getCOMList()!=0|| 0!= getUserSelect())
    {
        return;
    }

    if( ui->pushButtonAutoStart->text()=="开始测试"){

        ui->pushButtonAutoStart->setText("结束测试");
    }


    clearShow();
    serialThread = new SerialThread(this);
    serialThread->isTerminate = false;
    serialThread->start();

}

void FrameWindow::on_pushButton_custom_send_clicked()
{
    if(getCOMList()!=0 || getCustomCommands()!=0) {
        return;
    }

    customCommThread = new CustomCommandThread(this);
    customCommThread->start();
}


void FrameWindow::on_pushButton_manualSend_clicked()
{

    if(getCOMList()!=0 || getManualCommand()!=0) {
        return;
    }
    manualThread = new ManualThread(this);
    manualThread->start();


}


void FrameWindow::SelectInvert_clicked()
{
    int rowCount = ui->tableWidgetATCommand->rowCount();
    for(int i = 0; i<rowCount;i++){
        QTableWidgetItem* check = ui->tableWidgetATCommand->item(i,0);
        Qt::CheckState whether = check->checkState() == Qt::Checked ? Qt::Unchecked : Qt::Checked;
        ui->tableWidgetATCommand->item(i,0)->setCheckState(whether);

    }
}

void FrameWindow::on_pushButton_AutoMode_clicked()
{
    ui->stackedWidget_Pages->setCurrentIndex(0);
    ui->pushButton_AutoMode->setStyleSheet("color: red");
    ui->pushButton_ManualMode->setStyleSheet("color: black");
    ui->pushButton_BeidouMode->setStyleSheet("color: black");

}

void FrameWindow::on_pushButton_ManualMode_clicked()
{
    ui->stackedWidget_Pages->setCurrentIndex(1);
    ui->pushButton_AutoMode->setStyleSheet("color: black");
    ui->pushButton_ManualMode->setStyleSheet("color: red");
    ui->pushButton_BeidouMode->setStyleSheet("color: black");
}

void FrameWindow::on_pushButton_BeidouMode_clicked()
{
    ui->stackedWidget_Pages->setCurrentIndex(2);
    //设置字体颜色用函数setStyleSheet("color: red);
    ui->pushButton_AutoMode->setStyleSheet("color: black");
    ui->pushButton_ManualMode->setStyleSheet("color: black");
    ui->pushButton_BeidouMode->setStyleSheet("color: red");

    //ui->pushButton_BeidouMode->setStyleSheet("background: rgb(170,170,255)");
}



void FrameWindow::slot_finished_beidou_COM(QString comName)
{
    if(comName.isEmpty()){
        QMessageBox::warning(this,"北斗串口识别","没有识别北斗通信串口。\n可以重新上电通信模块后尝试！");
        ui->pushButton_beidouCOM->setEnabled(true);
        return;
    }


    beidouObject = nullptr;
    beidouObject = new BeidouObject(comName);

    connect(beidouObject, SIGNAL(receive_data(QByteArray)), this, SLOT(onReceivdBeidou(QByteArray))
            , Qt::QueuedConnection);
    connect(beidouObject, SIGNAL(transfer_result(QStringList)), this, SLOT(onTransfer_result(QStringList))
            , Qt::QueuedConnection);



    ui->pushButton_beidouCOM->setEnabled(true);
    ui->pushButton_beidouCOM->setText("关闭") ;
    ui->label_beidou_COM->setText("   "+comName);

    //将图片放入label，使用setPixmap,注意指针*img
    ui->label_beidou_port_image->setPixmap(QPixmap::fromImage(*img_good));

    setBeiDouMode(0);
    ui->comboBox_Mode->setCurrentIndex(0);
    on_pushButton_BeidouMode_clicked();

}



void FrameWindow::OpenAndSetMode(QString comName){

    //QImage *img=new QImage; //新建一个image对象

    if(img_good==nullptr){
        img_good = new QImage();//新建一个image对象
        img_good->load(":/new/prefix1/images/succes0.2.png"); //将图像资源载入对象img，注意路径，可点进图片右键复制路径

    }

    if(img_bad==nullptr){
        img_bad = new QImage();
        img_bad->load(":/new/prefix1/images/bad0.2.png");
    }


    if(ui->pushButton_beidouCOM->text() == "打开"){  // mens is open

        ui->pushButton_beidouCOM->setEnabled(false) ;

        // 识别北斗串口
        BeiDouPower* bdPower = new BeiDouPower(this);
        bdPower->start();

        // 北斗工作模式设置和接收工作，在BeiDouPower识别后，在slot_finished_beidou_COM中启动！

    }else if (ui->pushButton_beidouCOM->text() == "关闭") {

        emit beidouObject->signal_stop();
        beidouObject->func_stop(5000);

        ui->pushButton_beidouCOM->setText("打开");
        ui->label_beidou_COM->setText("   ----   ");
        //设置串口关闭时的图片
        ui->label_beidou_port_image->setPixmap(QPixmap::fromImage(*img_bad));
    }


}

void FrameWindow::on_pushButton_beidouCOM_clicked()
{


    DialogWait *dlgWait = new DialogWait();
    dlgWait->show();

    //name_BD_COM = "COM7"
    OpenAndSetMode(name_BD_COM);

    emit dlgWait->end_waitting();

}


void FrameWindow::on_comboBox_Mode_activated(int index)
{

    ui->textEdit_Longitudwe->setText("");
    ui->textEdit_Latitude->setText("");
    ui->textEdit_High->setText("");
    ui->textEdit_Time->setText("");

    if(beidouObject!=nullptr){
        setBeiDouMode(index);
    }

}




void FrameWindow::setBeiDouMode(int index)
{

    QString mode;

    beidouThread= new BDSetModelThread(this);

    switch (index) {
    case 0:{
        mode = "$PCAS04,2*1B"; //单北斗模式
        break;

    }
    case 1:{
        mode = "$PCAS04,1*18"; //单GPS模式
        break;

    }
    case 2:{
        mode = "$PCAS04,3*1A"; //北斗+GPS模式
        break;

    }
    default:{
        mode = "$PCAS04,2*1B"; //单北斗模式
    }

    }

    beidouThread->command = mode;
    beidouThread->start();

}




void FrameWindow::on_actionAbout_triggered()
{
    DialogAbout *about = new DialogAbout();

    about->show();
    // constrain constraint of present layer
    // micro/macro,opinion of court


    DialogWait *dlgWait = new DialogWait();
    //设置进度对话框采用模态方式进行，即显示进度的同时，其他窗口将不响应输入信号
    dlgWait->setWindowModality(Qt::WindowModal);
    dlgWait->show();



}
